#include <stdio.h>
#include <stdlib.h>

typedef struct TNode*BinTree;
struct TNode
{
    int     Key;
    BinTree Left;
    BinTree Right;
};

BinTree BuildTree(); /* details omitted */
int KthLargest(BinTree T,int X);

int main()
{
    BinTree T;
    int     X;
    
    T=BuildTree();
    scanf("%d",&X);
    printf("%d",KthLargest(T,X));
    
    return 0;
}
/* Your function will be put here */
int aaa(BinTree T,int X,int*cnt)
{
    if(!T)return 0;
    if(aaa(T->Right,X,cnt))return 1;
    ++*cnt;
    if(T->Key==X)
        return 1;
    if(aaa(T->Left,X,cnt))return 1;
    return 0;
}
int KthLargest(BinTree T,int X)
{
    int c=0;
    if(aaa(T,X,&c))
        return c;
    return 0;
}